﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Algorithms.Tools;

/*
 * TH07 Groep 10
 * ----------------------------------------------------------------------------------
 * Versie   Door        Commentaar
 * 0.1      Mike        Opzet en programmeer werk
 * 0.2      Luca        Optimalisatie code
 *                      Hernoemen variabelen en functies
 *                      overbodige code verwijderd 
 *                      crop image naar eigen tool classe verplaatst.
 *               
 */


namespace THO7AlgoritmTimerApplication
{
    public class OCR
    {

        #region private variables
        private Bitmap sourceImage;
        private static List<CharFeature> trainedChars;
        private CharacterTrainer characterTrainer = new CharacterTrainer();
        #endregion

        #region constructors
        /// <summary>
        /// Constructor
        /// </summary>
        public OCR()
        {
            if (trainedChars == null)
            {
                trainedChars = new List<CharFeature>();
            }
        }
        /// <summary>
        /// Constructor with bitmap soruce
        /// </summary>
        /// <param name="source"></param>
        public OCR(Bitmap source)
            : base()
        {
            sourceImage = source;
        }
        #endregion

        #region public functions
        /// <summary>
        /// Train the OCR on a specific font(s)
        /// </summary>
        /// <param name="font">string[]</param>
        public void Train(string[] font)
        {
            characterTrainer.TrainFromFonts(font);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="character"></param>
        /// <param name="charImage"></param>
        public void TrainChar(char character, VisionImage charImage)
        {
            CharFeature cf = new CharFeature(charImage);
            cf.CalculateFeatures();
            trainedChars.Add(cf);
        }

        /// <summary>
        /// Recoginze a character
        /// </summary>
        /// <param name="charImage"></param>
        /// <returns></returns>
        public char RecognizeChar(VisionImage charImage)
        {
            Character character = new Character();
            character.CalculateFromImage(charImage);
            return characterTrainer.GetCharacterFromCharacter(character);
        }
        /// <summary>
        /// Return charactertrainer image
        /// </summary>
        /// <returns></returns>
        public VisionImage GetImg()
        {
            return characterTrainer.TestImage;
        }


        #endregion
    }
}
